<template>
  <div class="app-container bg-gray">
    <el-row class="box-1">
      <el-col :span="24">
        <el-card>
          <div class="header">
            <div>
              <el-select v-model="searchTerms.areaId" placeholder="所属区域" class="select" clearable @change="getData">
                <el-option v-for="item in areaList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
              <el-select v-model="searchTerms.status" placeholder="转单状态" class="select" clearable @change="getData">
                <el-option :value="1" label="待处理" />
                <el-option :value="3" label="已转单" />
                <el-option :value="2" label="已驳回" />
              </el-select>
              <el-date-picker
                v-model="searchTerms.date"
                class="picker"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="getData"/>
              <el-input v-model="searchTerms.searchValue" placeholder="请输入姓名或手机号码" class="search-input" @change="getData"/>
              <el-button type="success" class="bg-green" icon="el-icon-search" @click="getData">搜索</el-button>
            </div>
          </div>
          <el-table v-loading="tableLoading" :data="tableData" :max-height="tableMaxHeight" border highlight-current-row @sort-change="handleSortChange">
            <el-table-column prop="id" label="ID" width="65" header-align="center" align="center" sortable/>
            <el-table-column prop="old_admin_name" label="转单网格员" min-width="120" header-align="center" align="center"/>
            <el-table-column prop="old_admin_mobile" label="联系方式" min-width="160" header-align="center" align="center"/>
            <el-table-column prop="street_name" label="所属区域" min-width="120" header-align="center" align="center"/>
            <!--<el-table-column prop="description" label="反馈详情" min-width="300">
              <template slot-scope="scope">
                <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{{ scope.row.description }}</div>
              </template>
            </el-table-column>-->
            <el-table-column prop="type_name" label="问题类别" min-width="120" header-align="center" align="center">
              <template slot-scope="scope">
                <el-tag type="info">{{ scope.row['type_name'] }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="change_remarks" label="网格员备注" min-width="300" header-align="center" align="center"/>
            <el-table-column prop="created_at" label="提交时间" min-width="160" header-align="center" align="center" sortable/>
            <el-table-column prop="verify_time" label="处理时间" min-width="160" header-align="center" align="center" sortable>
              <template slot-scope="scope">
                {{ scope.row['verify_time'] || '--' }}
              </template>
            </el-table-column>
            <el-table-column prop="now_admin_name" label="接单网格员" min-width="120" header-align="center" align="center">
              <template slot-scope="scope">
                {{ scope.row['now_admin_name'] || '--' }}
              </template>
            </el-table-column>
            <el-table-column prop="status" label="转单状态" min-width="120" header-align="center" align="center" fixed="right">
              <template slot-scope="scope">
                <el-tag v-if="scope['row']['status']===1" type="danger">待处理</el-tag>
                <el-tag v-else-if="scope['row']['status']===2" type="warning">已驳回</el-tag>
                <el-tag v-else-if="scope['row']['status']===4" type="warning">已解决</el-tag>
                <el-tag v-else type="success">已转单</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="200" header-align="center" align="center" fixed="right">
              <template slot-scope="scope">
                <el-button type="primary" size="small" icon="el-icon-search" @click="toDetails(scope['row'])" >详情</el-button>
                <el-button v-if="scope['row']['status']===1&&scope['row']['work_order_status']!==3" type="success" size="small" icon="el-icon-s-check" class="bg-green" @click="toHandle(scope['row'])">处理</el-button>
                <!--<el-button v-if="queryMatch(223)" type="danger" size="small" icon="el-icon-delete" @click="toDelete(scope['row'])" >删除</el-button>-->
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            :current-page.sync="currentPage"
            :page-size="pageSize"
            :page-sizes="pageSizes"
            :total="total"
            class="pagination"
            layout="total, sizes, prev, pager, next, jumper"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"/>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { handleSortChange, handleSizeChange, handleCurrentChange, parseTime } from '@/utils/table';
export default {
  data() {
    return {
      searchTerms: {
        areaId: '',
        status: '',
        searchValue: '',
        date: []
      },

      areaList: [],

      // 表格相关数据
      downloadLoading: false,
      tableMaxHeight: document.documentElement.clientHeight - 280,
      // 表格相关参数
      tableLoading: false,
      currentPage: 1,
      pageSize: 10,
      pageSizes: [5, 10, 20, 50, 100, 1000],
      total: 0,
      tableData: []
    }
  },
  watch: {},
  created() {
    this.getData();
    this.getAreaList();
  },

  methods: {
    handleCurrentChange, handleSizeChange, handleSortChange, parseTime,
    getData(order) {
      this.tableLoading = true
      order || (order = {})
      const url = 'workorder/changeOrderList'
      const data = {
        pageNo: this.currentPage,
        pageSize: this.pageSize,
        searchKey: this.searchTerms.searchValue,
        street_id: this.searchTerms.areaId,
        status: this.searchTerms.status
      }
      this.searchTerms.date && this.searchTerms.date.length !== 0 && (data.startTime = this.searchTerms.date[0] + ' 00:00:00', data.endTime = this.searchTerms.date[1] + ' 23:59:59')
      order.sortName && (data.sortName = order.sortName)
      order.sortOrder && (data.sortOrder = order.sortOrder)
      this.$store.dispatch('GetConnect', { url, data }).then(res => {
        this.tableData = res.data.rows;
        this.total = res.data.total;
        this.tableLoading = false;
      }).catch((e) => {
        this.tableLoading = false
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    /**
     *  获取区域列表
     */
    getAreaList() {
      const url = 'workorder/getNoPageStreet'
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.areaList = res.data
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    // 跳转详情
    toDetails(row){
      this.$router.push({
        path: '/workOrder/transferInfo',
        query: {
          id: row.id
        }
      })
    },

    // 跳转详情
    toHandle(row){
      this.$router.push({
        path: '/workOrder/transferHandle',
        query: {
          id: row.id
        }
      })
    },

    toDelete(row) {
      this.$confirm('此操作将删除该工单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const url = 'workorder/delWorkOrder/' + row.id
        this.$store.dispatch('GetConnect', { url }).then(res => {
          this.$message.success(res.msg)
          this.getData()
        }).catch(e => {
          this.$message.error(e.msg)
        })
      })
    }
  }
}
</script>

<style lang="scss" type="text/scss" scoped>
  @import '../../../../styles/index.scss';
  .box-1 {
    .header {
      @include flex-row(center, space-between);
      padding-bottom: 15px;
      .search-input {
        width: 240px;
      }
    }
  }
</style>
